package com.zzjx.demo.publishEnum;

import com.zzjx.demo.listener.UserInfoEventBusListener;
import com.zzjx.demo.util.EventBusUtils;

/**
 * 事件枚举
 * <li>发送事件</li>
 * <pre>
 *     EventBusEnum.MODIFY_INFO_EVENT.postEvent(new Object[]{"a",i+""})
 * </pre>
 * <li>消费事件</li>
 * <pre>
 *     EventBusEnum.MODIFY_INFO_EVENT.registerEvent(new EventBusListener(@Override public void onEvent(Object event){System.err.println(event);}));
 * </pre>
 *
 * @author zhaojiaxu
 * @date 2022/02/20 15:37
 **/
public enum EventBusEnum {
    MODIFY_INFO_EVENT("infoState", "修改用户的基本信息"),
    MODIFY_COMPANY_EVENT("companyState", "修改用户申报信息"),
    MODIFY_VAT_EVENT("vatState", "修改用户增票资质信息");
    private String code;
    private String name;

    public <T> void postEvent(T event){
        EventBusUtils.postEvent(getCode(),event);
    }
    public void registerEvent(UserInfoEventBusListener listener){
        EventBusUtils.registerEvent(getCode(),listener);
    }

    EventBusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public EventBusEnum setCode(String code) {
        this.code = code;
        return this;
    }

    public String getName() {
        return name;
    }

    public EventBusEnum setName(String name) {
        this.name = name;
        return this;
    }
}

